package com.hc.music.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.music.common.R;
import com.hc.music.dao.ListSongMapper;
import com.hc.music.entity.ListSong;
import com.hc.music.service.ListSongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ListSongServiceImpl extends ServiceImpl<ListSongMapper,ListSong> implements ListSongService {
    @Autowired
    ListSongMapper listSongMapper;
    @Override
    public R addListSong(ListSong listSong) {
        if(listSongMapper.insert(listSong) >0){
            return R.success("添加成功");
        }else {
            return R.error("添加失败");
        }
    }

    @Override
    public R updateListSongMsg(ListSong listSong) {
        return null;
    }

    @Override
    public R deleteListSong(Integer songId,Integer songListId) {
        QueryWrapper<ListSong> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("song_id",songId);
        queryWrapper.eq("song_list_id",songListId);
        if(listSongMapper.delete(queryWrapper) > 0){
            return R.success("删除成功");
        }else {
            return R.error("删除失败");
        }
    }

    @Override
    public List<ListSong> allListSong() {
        return listSongMapper.selectList(null);
    }

    @Override
    public R listSongOfSongId(Integer songListId) {
        QueryWrapper<ListSong> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("song_list_id",songListId);
        return R.success("查询歌单成功",listSongMapper.selectList(queryWrapper));
    }
}
